package com.zyao89.view.zloading;

import ohos.agp.components.Component;
import ohos.agp.components.Image;
import ohos.agp.render.Canvas;
import ohos.agp.render.ColorFilter;
import ohos.agp.utils.Color;
import ohos.app.Context;


/**
 * Created by zyao89 on 2017/3/19.
 * Contact me at 305161066@qq.com or zyao89@gmail.com
 * For more projects: https://github.com/zyao89
 * My Blog: http://zyao89.me
 */

public class ZLoadingDrawable extends Image implements Component.DrawTask {
    private final static String TAG = "Zloading ZLoadingDrawable";
    private ZLoadingBuilder mZLoadingBuilder;
    public ZLoadingDrawable(Context context) {
        super(context);
    }

    public void setmZLoadingBuilder(ZLoadingBuilder mZLoadingBuilder) {
        this.mZLoadingBuilder = mZLoadingBuilder;
    }

    void initParams(Context context, Color color) {
        if (mZLoadingBuilder != null) {
            mZLoadingBuilder.init(context);
            mZLoadingBuilder.initParams(context, color);
        }
    }

    public void setColorFilter(ColorFilter colorFilter) {
        this.mZLoadingBuilder.setColorFilter(colorFilter);
    }

    public void start() {
        this.mZLoadingBuilder.start();
    }

    public void stop() {
        this.mZLoadingBuilder.stop();
    }

    public boolean isRunning() {
        return this.mZLoadingBuilder.isRunning();
    }

    @Override
    public int getWidth() {
        return (int) this.mZLoadingBuilder.getIntrinsicWidth();
    }

    @Override
    public int getHeight() {
        return (int) this.mZLoadingBuilder.getIntrinsicHeight();
    }

    @Override
    public void onDraw(Component component, Canvas canvas) {
        component.setComponentSize(getWidth(), getHeight());
        this.mZLoadingBuilder.draw(canvas);
    }
}

